package com.wzh.yebServe.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzh.yebServe.mapper.RoleMapper;
import com.wzh.yebServe.pojo.ResultBean;
import com.wzh.yebServe.pojo.Role;
import com.wzh.yebServe.service.IRoleService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/16 15:45
 * @Description:
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Override
    public List<Role> getAllRoles() {
        return list();
    }

    @Override
    public ResultBean addRole(Role role) {
        if (!role.getName().startsWith("ROLE_")){
            role.setName("ROLE_"+role.getName());
        }
        boolean save = save(role);
        if (save) {
            return ResultBean.success("添加新角色成功");
        }
        return ResultBean.error("添加失败") ;
    }

    @Override
    public ResultBean updateRole(Role role) {
        boolean b = updateById(role);
        if (b){
            return ResultBean.success("修改角色信息成功");
        }
        return ResultBean.error("修改失败");
    }

    @Override
    public ResultBean deleteRole(Integer id) {
        boolean b = removeById(id);
        if (b) {
            return ResultBean.success("删除成功");
        }
        return ResultBean.error("删除失败");
    }

    @Override
    public ResultBean deleteRoleByids(Integer[] ids) {
        boolean b = removeBatchByIds(Arrays.asList(ids));
        if (b) {
            return ResultBean.success("删除成功");
        }
        return ResultBean.error("删除失败");
    }

    @Override
    public ResultBean updateUserRole(Integer userId, Integer[] rids) {
        return null;
    }


}
